												
<!DOCTYPE html>
<html lang="zh-cn">
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <#include "/common/meta.ftl"/>
	    <#include "/common/form.ftl"/>
		<script>
		$(function(){
			$("#form").validate({
					rules: {
						attachmentName : {required:true},
						file : {required:true},
						attachmentOrder : {digits:true}
					},
					errorElement: "div",
					errorPlacement: function(error, element) {
						error.appendTo($(element).parent());
						$(element).parent().addClass("has-error");
						$(error).addClass("help-block alert-danger");
					},
					success: function(label) {
						$(label).parent().removeClass("has-error");
						$(label).remove();
					}
				})
			});
			function save(){
				if($("#form").valid()){
					var form = $("#form");
					var options = {
						url: '${_b}/admin/uploadAttachment',
						type: 'post',
						success: function(result){
							var dataObj = $.parseJSON(result);	
								if(dataObj.success){							
									closeSelf();																	 								
								}else{
								 	closeSelf();					 	
								}
						}
					}				
					form.ajaxSubmit(options);
				}			
			}
		    //拷贝标题
			function copyName(fileName){
				fileName=document.getElementById("attachmentName").value;
				fileInfo=document.getElementById("file").value;
				if(fileName==""){
					document.getElementById("attachmentName").value=getFileName(fileInfo);
				}
			}
			//获取附件名称
			function getFileName(tmpstr){
				  extendIndex=tmpstr.lastIndexOf('.');
				  if(extendIndex==-1) 
					extendIndex=tmpstr.length;
					beginIndex=tmpstr.lastIndexOf('\\');
				  if(beginIndex==-1)
					beginIndex=tmpstr.lastIndexOf('/');
				  beginIndex++;	  
			      var str=tmpstr.substring(beginIndex,extendIndex);
			      return str;
			}	
		function closeSelf(){
			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			parent.layer.close(index);
		}
		</script>
	</head>
	<body style="padding:5px;">
		<div class="panel panel-primary">
			<div class="panel-body" style="padding:5px;padding-top:15px;">
			<form id="form" class="form-horizontal" role="form" method='post' enctype="multipart/form-data" action="./uploadAttachment">
				<input type="hidden" name="sourceId" value="${sourceId!''}">
				<table class="table table-condensed table-bordered table-form" style="width:560px;margin:0 auto;">
					<tbody>
						<tr>
					    	<th class="required">文件名称</th>
					    	<td>
					    		<input type='text'  name="attachmentName"  id='attachmentName' value='' class='form-control' placeholder=''/>
					    	</td>
					    </tr>
					    <tr>
					      	<th class="required">文件路径</th>
						    <td style="padding:4px;">
						    	<input type="file" name="file" id="file" onchange="copyName(this.value)"/>
						    </td>
					    </tr>
					    <tr>
					      	<th >文件说明</th>
						    <td style="padding:4px;">
						    	<input type='text'  name="attachmentMemo"  id='attachmentMemo' value='' class='form-control' placeholder=''/>
						    </td>
					    </tr>
					    <tr>
					      	<th >排序号</th>
						    <td style="padding:4px;">
						    	<input type='text'  name="attachmentOrder"  id='attachmentOrder' value='' class='form-control' placeholder=''/>
						    </td>
					    </tr>
					    <tr>
						    <td align="center" colspan="2">
						    	<button class="btn btn-primary"   onclick="save();" type="button"><i class="icon icon-save"></i> 保 存</button>
		             			<button class="btn btn-danger" onclick="closeSelf();" type="button"><i class="icon icon-times"></i> 关 闭</button>
						    </td>
					    </tr>
				  	</tbody>
				</table>		
				
				
				
				
				
				
				
				
				
				
				
				
			</form>
		  	</div>
		</div>
	</body>
</html>